import Util from '@/js_sdk/validator/util.js';
const db = uniCloud.database()
const publicData = {
	items: [{value: 1,name: '平台公告',},
		{value: 2,name: '普通通知'},
		{value: 3,name: '政策通知'},
	],
	target: [
		'全部可见'
	],
	towshipData: [{
			"value": "app",
			"text": "手机App"
		},
		{
			"value": "公众号",
			"text": "微信公众号"
		},
	],
	range: [{
			value: 0,
			text: "全部"
		},
		{
			value: 1,
			text: "公众号"
		},
		{
			value: 2,
			text: "手机App"
		},
		{
			value: 3,
			text: "未知"
		},
	],
	imagestyle: {
		"height": 160, // 边框高度
		"width": 160, // 边框宽度
		"border": { // 如果为 Boolean 值，可以控制边框显示与否
			"color": "#eee", // 边框颜色
			"width": "1px", // 边框宽度
			"style": "solid", // 边框样式
		}
	}
}

const publicFun = {
	// 选择平台公告
	radioChange(e) {
		let index =  e.detail.value
		this.formData.type = this.items[index-1]
	},
	// 选择 swiper
	onTarget(index){
		this.targetIndex = index
		this.formData.targetSend.platform = this.target[index]
	},
	// swiper 2
	onMultipleData(e){
		this.formData.targetSend.label_arr = e.detail.value?e.detail.value:[]
	},
	// swiper3 获取swiper3数据
	getPersonData(push=false){
		const db = uniCloud.database()
		db.collection("rider_users")
			.where(this.where)
			.field("user_id,name,avatar,is_online,status,create_date").orderBy("create_date desc")
		.skip(this.skip).limit(10).get({
				getOne: false,
				getCount: true,
		}).then(res => {
			// console.log(res.result)
			let data = res.result.data
			if (push) {
				this.personData.push(...data)
			}else {
				this.personData = data
			}
		})
		
	},
	// swiper3滚动到底部
	scrollBottom(event){
		this.skip += 10
		this.getPersonData(true)
	},
	// swiper3 下拉框
	changeDateSelect(ev){
		switch (ev) {
			case 0:
				this.where = {}
				break;
			case 1:
				this.where = {
					"register_env.uni_platform":"web"
				}
				break;
			case 2:
				this.where = {
					"register_env.uni_platform":"app"
				}
				break;
			default:
				const dbCmd = db.command
				this.where = {
					"register_env.uni_platform":dbCmd.neq('app').and(dbCmd.neq('web'))
				}
				break
		}
		this.getPersonData()
	},
	onBlurEdit(e){
		this.formData.abstract = Util.escapeSpecialCharacters(e.slice(0,80))
	},
}

export {
	publicData,
	publicFun
}